home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks '96 / Internet Chooser / Sample LDEFs 2.0 / (Sys 7) Icon LDEF / Icon LDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-27  |  3.4 KB  |  104 lines  |  [TEXT/KAHL]

  1. // File "Icon LDEF.c" - Icon Suite LDEF Routine  
  2. // This code is placed in the public domain for free use and distribution - MJS
  3. //
  4. //    6/27/95       Changed the Hilite Mode to use accessor functions
  5. //                  Properly save and restore Handle states - MJS
  6. //
  7. //   10/16/93        First released the LDEFs to the net - MJS
  8. //
  9. //    5/23/91       Original snippet which this is shamelessly based on,
  10. //                  by Steven Falkenburg, Apple DTS
  11.  
  12. // * **************************************************************************** * //
  13.  
  14. #include <GestaltEqu.h>
  15. #include <Icons.h>
  16.  
  17. // * **************************************************************************** * //
  18. // * **************************************************************************** * //
  19. // Universal Headers users can replace these with LM accessor functions
  20.  
  21. pascal unsigned char GetHiliteMode(void) = { 0x1EB8, 0x0938 }; /* MOVE.B 0x0938,(A7) */
  22. pascal void SetHiliteMode(unsigned char) = { 0x11DF, 0x0938 }; /* MOVE.B (A7)+,0x0938 */
  23.  
  24. // * **************************************************************************** * //
  25. // * **************************************************************************** * //
  26.  
  27. pascal void    main(short message, Boolean hilited, Rect *cellRect, Cell theCell,
  28.         short dataOffset, short dataLen, ListHandle theList) {
  29.     long response;
  30.     Point drawPt;
  31.     Rect iconRect, textRect;
  32.     Ptr cellData;
  33.     Handle iconHdl;
  34.     ListPtr theListPtr;
  35.     SignedByte hStateList, hStateCells;
  36.     FontInfo fontInfo;
  37.     
  38.     if (Gestalt(gestaltSystemVersion, &response) || (response < 0x0700)) return;
  39.     
  40.     // Lock down the handles
  41.     hStateList = HGetState((Handle) theList);
  42.     HLock((Handle) theList);
  43.     theListPtr = *theList;
  44.     hStateCells = HGetState((Handle) theListPtr->cells);
  45.     HLock((Handle) theListPtr->cells);
  46.     cellData = *(theListPtr->cells);
  47.     
  48.     GetFontInfo(&fontInfo);
  49.     SetRect(&iconRect, cellRect->left + (theListPtr->cellSize.h >> 1) - 16,
  50.             cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) - 16,
  51.             cellRect->left + (theListPtr->cellSize.h >> 1) + 16,
  52.             cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) + 16);
  53.     SetPt(&drawPt, (iconRect.left + iconRect.right) >> 1, 
  54.             iconRect.bottom + fontInfo.ascent + 2);
  55.  
  56.     switch (message) {
  57.         case lInitMsg:
  58.               break;
  59.  
  60.         case lDrawMsg:
  61.             EraseRect(cellRect);
  62.         case lHiliteMsg:
  63.             
  64.               if (dataLen > 0) {
  65.                   if (dataLen >= 4) {
  66.                       BlockMove(cellData + dataOffset, &iconHdl, 4);
  67.                       if (iconHdl)
  68.                           PlotIconSuite(&iconRect, 0, (hilited) ? ttSelected : 0, iconHdl);
  69.                         else if (hilited) PaintRect(&iconRect);
  70.                         else EraseRect(&iconRect);
  71.                       dataLen -= 4;
  72.                       dataOffset += 4;
  73.                       }
  74.                 
  75.                 // Condense if the text doesnt fit
  76.                 if (TextWidth(cellData, dataOffset, dataLen) >
  77.                         (cellRect->right - cellRect->left)) TextFace(condense);
  78.         
  79.                 SetRect(&textRect, drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1) - 2,
  80.                         drawPt.v - fontInfo.ascent - 1,
  81.                         drawPt.h + (TextWidth(cellData, dataOffset, dataLen) >> 1) + 2,
  82.                         drawPt.v + 2);
  83.  
  84.                 EraseRect(&textRect);
  85.                   MoveTo(drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1), drawPt.v);
  86.                 DrawText(cellData, dataOffset, dataLen);
  87.  
  88.                 if (hilited) {
  89.                     SetHiliteMode(GetHiliteMode() ^ (1L << hiliteBit));    
  90.                       InvertRect(&textRect);
  91.                       }
  92.                   }
  93.         
  94.               break;
  95.  
  96.         case lCloseMsg:
  97.               break;
  98.             }
  99.     
  100.     // Restore the Handles
  101.     HSetState((Handle) theListPtr->cells,hStateCells);
  102.     HSetState((Handle) theList, hStateList);
  103.     }
  104.